import request from '@/utils/request'
import { getDictionaryDataSelector } from '@/api/systemData/dictionary'
import CustomForm from './Form/index.vue'
import RecordsForm from './Records/index.vue'
// import ExportBox from './ExportBox'
import { previewDataInterface } from '@/api/systemData/dataInterface'
export default {
  components: { CustomForm, RecordsForm },
  data() {
    return {
      showAll: false,
      query: {
        category: undefined,
        keywords: undefined,
        status: undefined
      },
      list: [],
      listLoading: true,
      multipleSelection: [],
      total: 0,
      listQuery: {
        currentPage: 1,
        pageSize: 20,
        sort: 'desc',
        sidx: ''
      },
      formVisible: false,
      recordsVisible: false,
      exportBoxVisible: false,
      columnList: [{ prop: 'question', label: '问题文本' }, { prop: 'sourse', label: '来源' }, { prop: 'category', label: '分类' }, { prop: 'keywords', label: '关键字' }, { prop: 'status', label: '状态' }, { prop: 'solutions', label: '解决方案' }, { prop: 'createTime', label: '创建时间' }, { prop: 'createUserName', label: '创建用户' }, { prop: 'updateTime', label: '修改时间' }, { prop: 'updateUserName', label: '修改用户' }],
      categoryOptions: [],
      statusOptions: [],
      sourseOptions: []
    }
  },
  computed: {},
  mounted() {
    this.$store.dispatch("base/getDictionaryData", { sort: "FqaCategory" }).then((res) => {
      this.categoryOptions = res;
    });
    this.$store.dispatch("base/getDictionaryData", { sort: "FqaSourse" }).then((res) => {
      this.sourseOptions = res;
    });

    this.$store.dispatch("base/getDictionaryData", { sort: "FqaStatus" }).then((res) => {
      console.log(res, 'FqaStatus')
      this.statusOptions = res;
    });
  },
  created() {
    this.initData()
    // this.getcategoryOptions()
    // this.getstatusOptions()
  },
  methods: {
    getcategoryOptions() {
      getDictionaryDataSelector('328809012411761925').then(res => {
        this.categoryOptions = res.data.list
      })
    },
    getstatusOptions() {
      getDictionaryDataSelector('451539650159314181').then(res => {
        this.statusOptions = res.data.list
      })
    },
    initData() {
      this.listLoading = true
      let _query = {
        ...this.listQuery,
        ...this.query
      }
      let query = {}
      for (let key in _query) {
        if (Array.isArray(_query[key])) {
          query[key] = _query[key].join()
        } else {
          query[key] = _query[key]
        }
      }
      request({
        url: `/api/extend/fqaentries`,
        method: 'GET',
        data: query
      }).then(res => {
        this.list = res.data.list
        this.total = res.data.pagination.total
        this.listLoading = false
      })
    },
    handleDel(id) {
      this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
        type: 'warning'
      })
        .then(() => {
          request({
            url: `/api/extend/fqaentries/${id}`,
            method: 'DELETE'
          }).then(res => {
            this.$message({
              type: 'success',
              message: res.msg,
              onClose: () => {
                this.initData()
              }
            })
          })
        })
        .catch(() => {})
    },
    addOrUpdateHandle(id, isDetail) {
      this.formVisible = true
      this.$nextTick(() => {
        this.$refs.CustomForm.init(id, isDetail)
      })
    },
    addHandle(id) {
      this.recordsVisible = true
      this.$nextTick(() => {
        this.$refs.RecordsForm.init(id)
      })
    },
    search() {
      this.listQuery = {
        currentPage: 1,
        pageSize: 20,
        sort: 'desc',
        sidx: 'createTime'
      }
      this.initData()
    },
    refresh(isrRefresh) {
      this.formVisible = false
      this.recordsVisible = false
      if (isrRefresh) this.reset()
    },
    reset() {
      for (let key in this.query) {
        this.query[key] = undefined
      }
      this.listQuery = {
        currentPage: 1,
        pageSize: 20,
        sort: 'desc',
        sidx: 'createTime'
      }
      this.initData()
    }
  }
}
